﻿using B.S.BsicData.Api.Writer.Application.Command;
using B.S.BsicData.Domain;
using B.S.BsicData.ErrorCode.Entity;
using B.S.BsicData.Infartrans;
using MediatR;

namespace B.S.BsicData.Api.Writer.Application.CommandHandler
{
    public class UpdateWhouselockCommandHandler : IRequestHandler<UpdateWhouselockCommand, ApiResult<int>>
    {
        private readonly IBaseReository<WHouseModeles> whRepo;

        public UpdateWhouselockCommandHandler(IBaseReository<WHouseModeles> whRepo)
        {
            this.whRepo = whRepo;
        }
        public async Task<ApiResult<int>> Handle(UpdateWhouselockCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var model = whRepo.GetAll().Where(p => p.WhouseNum == request.WhouseNum).FirstOrDefault();
            if (model != null)
            {
                model.Lock = true;
                whRepo.Update(model);
                result.Code = ApiENums.成功;
                result.Message = "成功";
                result.Data = 1;
            }
            return await Task.FromResult(result);
        }
    }
}
